from objects.car_manager import CarManager
from objects.scoreboard import Scoreboard
from setup.screen import start_screen, screen, listen_key
import time
from objects.player import Player

start_screen()
turtle = Player()
listen_key(turtle.go_up, "Up")

car_manager = CarManager()
scoreboard = Scoreboard()

game_is_on = True
while game_is_on:
    time.sleep(0.1)
    # if not turtle.up():
    #     turtle.reset_pos()
    screen.update()

    car_manager.create_car()
    car_manager.move_cars()

    for car in car_manager.cars:
        if car.distance(turtle) < 20:
            game_is_on = False
            scoreboard.game_over()

    if turtle.is_finished:
        turtle.go_to_start()
        car_manager.level_up()
        scoreboard.increase_level()


screen.exitonclick()
